package site.marqstree.kotlin.library.good.ui.fragment.cartlist

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import site.marqstree.kotlin.library.base.util.rxbus.RxBus
import site.marqstree.kotlin.library.good.ui.bean.CartVOBean
import site.marqstree.kotlin.library.good.ui.fragment.cartlist.event.EventAllSelectChange


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.fragment.cartlist
 * 文件名: CartFragPresenter
 * 创建者: marqstree
 * 创建时间: 2020/3/20 16:56
 * 描述: TODO
 */
class CartFragPresenter {

    lateinit var mAdapter:CartListAdapter
    lateinit var mRv:RecyclerView

    fun setAdapter(adapter: CartListAdapter){
        mAdapter = adapter
    }
    fun setRv(rv: RecyclerView){
        mRv = rv
    }

    fun clickSelectAll(view: View,cartVOBean: CartVOBean){
        cartVOBean.selectAll.set(
            !cartVOBean.selectAll.get()
        )
        //发送Item选择事件
        RxBus.send(EventAllSelectChange())
    }

    fun clickDelete(view: View,cartVOBean: CartVOBean){
        //若处于编辑模式
        if(!cartVOBean.mode.get()){
            var newGoods = cartVOBean.goods
                .filter {
                    !it.selected.get()
                }
            cartVOBean.goods = newGoods.toMutableList()
            mAdapter.setNewData(cartVOBean.goods)
        }
    }
}